<template>
  <lay-card>

    <template v-slot:body>
      <lay-row>
        <lay-col>
          <lay-table :loading="config.loading" :columns="config.columns" :page="config.page" @change="change"
            :data-source="config.data" class="project-grids">

            <template #toolbar>
              <lay-input v-model="config.search.name" size="sm" placeholder="搜索" suffix-icon="layui-icon-search"
                style="width: 20%;"></lay-input>

              <lay-button-group v-for="n in listbutton.toolbarbuttons" :key="n">
                <lay-button :size="n.size" :type="n.status" border-style="dashed" @click="Events(n, null)"> {{ n.name
                }}</lay-button>
              </lay-button-group>
            </template>
            <template v-slot:operator="{ row }">
              <span v-for="n in listbutton.rowbuttons" :key="n">
                <lay-tooltip :content="n.name" position="bottom" :is-dark="true">
                  <button class="a-button type--button is--circle" circle @click="Events(n, row)">
                    <lay-icon :type="n.icon" :color="n.color">

                    </lay-icon>
                  </button>
                </lay-tooltip>

              </span>

            </template>
          </lay-table>
        </lay-col>


      </lay-row>
    </template>
  </lay-card>
</template>
<script lang="ts">
export default {
  name: "mianwait"
}
</script>
<script lang="ts" setup>
import { ref, nextTick } from "vue";
import { layer } from "@layui/layer-vue";
import webosutils from 'webosutils';
import { useRoute } from 'vue-router';
import { ReleaseIcon } from '@layui/icons-vue';
import { useRouter } from 'vue-router';
import listurils from '../../utils/listutils';
import { LayerForm} from 'webos-form-design';
const router = useRouter();
const route = useRoute();
const listbutton = ref({
  rowbuttons: [] as any,
  toolbarbuttons: [] as any,
});
const size = ref("sm");
const config = ref({
  loading: true,
  data: [],
  page: {
    total: 0,
    limit: 10,
    current: 1,
    showRefresh: true,
    limits: [5,10,20,50,100,200]
  },
  columns: [
    // { key: 'checkbox', width: 50 },
    { type: 'checkbox', width: 50 },
        { key: 'title', title: '标题' },
        { key: 'sendername', title: '作者', },
        { key: 'stepname', title: '步骤', },
        { key: 'receivetime', title: '接收时间', },
    {
      title: "操作",
      ignoreExport: true,
      fixed: "right",
      customSlot: "operator",
      key: "operator"
    }
  ],
  api: "",
  search: {
    type: route.query.zhuanti,
    name: ""
  }
});

listurils.getButton(route.query.appid, config, listbutton).then((res: any) => {
  //加载完成后刷新列表

  if (res.success) {
    config.value.api = res.data.api;
    if (listbutton.value.toolbarbuttons.length > 0) {
      size.value = listbutton.value.toolbarbuttons[0].size;
    }
    listurils.searchEvent(config);
  } else {
    layer.notify({
      title: "Error",
      content: res.msg,
      icon: 2
    })
  }

});
const change = (p: any) => {

  config.value.page.current = p.current;
  config.value.page.limit = p.limit;
  listurils.searchEvent(config);
}
const Callback=()=>{
  listurils.searchEvent(config);
}
const Events = (ent: any, row: any) => {
  try {

    switch (ent.events) {
      case "editEvent":
      var query = new Object() as any;
      // query.fromid = row.fromid;
      // query.instanceid = row.instanceid;
      // query.zhuanti = route.query.zhuanti;
      query.instanceid = row.instanceid;
      query.taskid = row.id;
      query.groupid = row.groupid;
      query.flowid = row.flowid;
      query.stepid = row.stepid;
      query.tabname =encodeURIComponent(row.title);
    
      router.push({ path: "/oa/workrun/index", query: query })

        break;
      case "searchEvent":
        if (config.value.page) {
          listurils.searchEvent(config);
        }

        break;
      case "deleteEvent": listurils.removeRowEvent(ent, row, listurils.searchEvent, config);
        break;
      case "addEvent":
        if (ent.ispopup == 0) {
          var query = new Object() as any;
          query.fromid = ent.formid;
          query.instanceid = "";
          query.zhuanti = route.query.zhuanti;
          query.tabname = encodeURIComponent(ent.title);
          router.push({ path: ent.api, query: query })

        } else {
          listurils.addEvent(LayerForm, ent, { fromid: ent.formid, instanceid: "", callback: Callback }, {});

        }
        break;

      case "previewEvent": listurils.previewEvent(LayerForm, ent, row);
        break;
    }
  } catch (e) {
    layer.msg("按钮解析失败", { icon: 3, time: 1000 })
  }

}
</script>
<style scoped></style>

